package com.zzyl.controller.manager;

import com.zzyl.base.PageBean;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.dto.NursingProjectPageQueryDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理口")
public class NursingProjectController {

    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 分页条件查询护理项目
     * @param dto
     * @return
     */
    @ApiOperation("分页条件查询护理项目")
    @GetMapping
    public ResponseResult<PageBean<NursingProjectVo>> pageQuery(NursingProjectPageQueryDto dto) {
        log.info("分页条件查询护理项目:{}", dto);
        PageBean<NursingProjectVo> pageBean = nursingProjectService.pageQuery(dto);
        return ResponseResult.success(pageBean);
    }

    /**
     * 新增护理项目
     * @param nursingProjectDto
     * @return
     */
    @ApiOperation("新增护理项目")
    @PostMapping
    public ResponseResult addNursingProject(@RequestBody NursingProjectDto nursingProjectDto) {
        log.info("新增护理项目:{}", nursingProjectDto);
        nursingProjectService.addNursingProject(nursingProjectDto);
        return ResponseResult.success();
    }


    /**
     * 根据id查询护理项目
     * @param id
     * @return
     */
    @ApiOperation("根据id查询护理项目")
    @GetMapping("/{id}")
    public ResponseResult<NursingProjectVo> getNursingProjectById(@PathVariable Long id) {
        log.info("根据id查询护理项目:{}", id);
        NursingProjectVo nursingProjectVo = nursingProjectService.getNursingProjectById(id);
        return ResponseResult.success(nursingProjectVo);
    }

    /**
     * 编辑护理项目
     * @param nursingProjectDto
     * @return
     */
    @ApiOperation("编辑护理项目")
    @PutMapping
    public ResponseResult updateNursingProject(@RequestBody NursingProjectDto nursingProjectDto) {
        log.info("编辑护理项目:{}", nursingProjectDto);
        nursingProjectService.updateNursingProject(nursingProjectDto);
        return ResponseResult.success();
    }

    /**
     * 启用禁用护理项目
     * @param id
     * @param status
     * @return
     */
    @ApiOperation("启用禁用护理项目")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult enableOrDisableNursingProject(@PathVariable Long id, @PathVariable Integer status) {
        log.info("启用禁用护理项目，id:{}，status:{}", id, status);
        nursingProjectService.enableOrDisableNursingProject(id, status);
        return ResponseResult.success();
    }

    /**
     * 删除护理项目
     * @param id
     * @return
     */
    @ApiOperation("删除护理项目")
    @DeleteMapping("/{id}")
    public ResponseResult deleteNursingProject(@PathVariable Long id) {
        log.info("删除护理项目:{}", id);
        nursingProjectService.deleteNursingProject(id);
        return ResponseResult.success();
    }

    /**
     * 查询所有护理项目
     * @return
     */
    @ApiOperation("查询所有护理项目")
    @GetMapping("/all")
    public ResponseResult<List<NursingProjectVo>> getAllNursingProjects() {
        log.info("查询所有护理项目");
        List<NursingProjectVo> pageBean = nursingProjectService.getAllNursingProjects();
        return ResponseResult.success(pageBean);
    }
}
